<?php

class MypushNoticeModel extends Model
{
    public $tableName = 'my_push_notice';
    /**
     * 字段列表.
     *
     * @var unknown_type
     */
    protected $fields = array(
        0          => 'id',
        1          => 'push_type', //推送类型，1：点赞，2：评论，3：举报，4：转发，5：取消点赞，6：删除评论
        2          => 'digg_id',
        3          => 'uid',
        4          => 'digg_id',
        5          => 'comment_id',
        6          => 'feed_id',
        7          => 'feed_title',
        8          => 'feed_content',
        9          => 'feed_topic_name',
        10         => 'status', //0未读，1：已读，4：删除
        11         => 'addtime',
        12         => 'is_send', //是否发送
        13         => 'to_uid', //被操作【点赞，评论】uid
        '_autoinc' => true,
        '_pk'      => 'id',
    );

    //加入推送消息表
    public function addPushMessage($uid , $to_uid , $digg_id = 0 , $feed_id = 0, $comment_id = 0, $push_type = 1){
        $data['to_uid'] = $to_uid;
        $data['uid'] = $uid;
        $data['feed_id'] = $feed_id;
        if(!$feed_id){
            return;
        }
        $feed_info               = model('Feed')->getFeedInfo($feed_id);
        $data['feed_title']      = $feed_info['feed_title'];
        $data['feed_content']    = $feed_info['feed_content'];
        $data['feed_topic_name'] = $feed_info['topic_name'];
        $data['status'] = 0;
        $data['is_send'] = 0;
        $data['addtime'] = time();
        if($push_type == 1){
            if($digg_id && $uid && $feed_id){
                $data['push_type'] = 1;
                $data['digg_id'] = $digg_id;
                $this->add($data);
            }
        }else if($push_type == 2){
            if($feed_id && $uid && $comment_id){
                $data['push_type'] = 2;
                $data['comment_id'] = $comment_id;
                $this->add($data);
            }
        }else if($push_type == 5){
            //取消点赞
            if($feed_id && $uid && $comment_id){
                $data['push_type'] = 5;
                $this->add($data);
            }
        }else if($push_type == 6){
            //删除评论
            if($feed_id && $uid && $comment_id){
                $data['push_type'] = 6;
                $this->add($data);
            }
        }

        else{
            return false;
        }

    }
}
